<include file="./Template/Admin/header.html" title="添加权限" />
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加权限</h5>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-2">
                            <a href="{:U('Admin/Rule/index')}" class="btn btn-outline btn-primary">返回权限列表</a>
                        </div>
                    </div>
                    <form class="form-horizontal m-t" id="addForm" method="post" action="{:U('Admin/Rule/Save')}">
                        <input type="hidden" name="id" value="{$ruleInfo.id}" class="form-control" />
                        <input type="hidden" name="pid" value="{$ruleInfo.pid}" class="form-control" />
                        <div class="form-group">
                            <label class="col-sm-3 control-label">权限名称:</label>
                            <div class="col-sm-8">
                                <input id="title" name="title" class="form-control" value="{$ruleInfo.title}" type="text">
                                <span class="help-block m-b-none"></span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">权限:</label>
                            <div class="col-sm-8">
                                <input id="name" name="name" class="form-control" value="{$ruleInfo.name}" type="text">
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 请输入&nbsp;&nbsp;&nbsp;/模块/控制器/方法</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">状态:</label>
                            <div class="col-sm-8">
                                <input type="checkbox" class="js-switch form-control" value="1" data-value="{$ruleInfo.status}" name="status" id="status" <if condition="$ruleInfo.status eq 1"> checked</if>/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">提交</button>
                                <button class="btn btn-white" type="reset"  onclick="history.go(-1)">取消</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="__ADMIN__js/jquery.min.js"></script>
<script src="__ADMIN__js/bootstrap.min.js"></script>
<script src="__ADMIN__js/plugins/layer.3/layer.js"></script>
<script src="__ADMIN__js/common.js"></script>
<script src="__ADMIN__js/content.min.js"></script>
<script src="__ADMIN__js/plugins/validate/jquery.validate.min.js"></script>
<script src="__ADMIN__js/plugins/validate/messages_zh.min.js"></script>
<script src="__ADMIN__js/plugins/switchery/switchery.js"></script>
<script>
    var elem = document.querySelector('.js-switch');
    var init = new Switchery(elem);

    $(function(){
        // 姓名格式验证
        jQuery.validator.addMethod("checkname", function(value, element) {
            if(/^[a-zA-Z0-9_-]{3,16}$/.test(value)) {
                return true;
            }else{
                return false;
            }
        }, "");
        $.validator.setDefaults({
            highlight: function (e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            }, success: function (e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            }, errorElement: "span", errorPlacement: function (e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
        }), $().ready(function () {
            var e = "<i class='fa fa-times-circle'></i> ";

            $("#addForm").validate({
                rules: {
                    title: "required",
                    name: "required"
                },
                messages: {
                    title: e + "请输入权限名称",
                    name: e + "请输入权限,格式为  /模块/控制器/方法"
                },
                submitHandler: function(form){
                    var data = new  FormData(document.getElementById('addForm'));
                    $.ajax({
                        url:$(form).attr('action'),
                        type:"post",
                        data:data,
                        cache: false,
                        processData: false,
                        contentType: false,
                        success:function(data){
                            if(data.status > 0){
                                common.error(data.msg);
                            }else{
                                common.success(data.msg,"{:U('Admin/Rule/index')}");
                            }
                        },
                        dataType:'JSON'
                    });
                }
            });
        });

    });
</script>
</body>
</html>
